package com.jwsoft.manager.core.integration.bigScreen.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictQueryVO;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.jwsoft.manager.common.vo.bigScreen.analysisXq.GetDictVO;
import com.jwsoft.manager.common.vo.bigScreen.analysisYbm.*;
import com.jwsoft.manager.common.vo.eduSjtj02.EduSjtj02GetSbJzzVO;
import com.jwsoft.manager.common.vo.eduSjtj02.EduSjtj02InVO;
import com.jwsoft.manager.common.vo.eduSjtj02.EduSjtj02RankVO;
import com.jwsoft.manager.core.dao.model.EduArea;
import com.jwsoft.manager.core.dao.model.EduSjtj02;
import com.jwsoft.manager.core.dao.model.EduSjtj03;
import com.jwsoft.manager.core.dao.service.EduAreaService;
import com.jwsoft.manager.core.dao.service.EduSjtj02Service;
import com.jwsoft.manager.core.dao.service.EduSjtj03Service;
import com.jwsoft.manager.core.integration.EduSjtj03Integration;
import com.jwsoft.manager.core.integration.bigScreen.AnalysisYbmIntegration;
import com.jwsoft.manager.core.util.EduHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;

import javax.management.Query;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

@ApiService(funcCode = "AnalysisYbm", title = "大屏接口")
public class AnalysisYbmIntegrationImpl implements AnalysisYbmIntegration {
    @Autowired
    EduSjtj03Service eduSjtj03Service;
    @Autowired
    EduHelper eduHelper;
    @Autowired
    CommonIntegration commonIntegration;
    @Autowired
    private EduSjtj02Service eduSjtj02Service;
    @Autowired
    EduAreaService eduAreaService;
    @Autowired
    DictIntegration dictIntegration;
    @Override
    public YbmOverviewVO getYbmOverView(YbmOverviewQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        YbmOverviewVO ybmOverviewVO=new YbmOverviewVO();
        ybmOverviewVO.setYear(vo.getYear());
        ybmOverviewVO.setAreaCode(vo.getAreaCode());
        //学校总数
        QueryWrapper<EduSjtj03> schoolCountWrapper=new QueryWrapper<>();
        schoolCountWrapper.select("sum(target_num) as schoolCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0042");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            schoolCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            schoolCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> schoolCountMap=eduSjtj03Service.getMap(schoolCountWrapper);
        if(!ObjectUtils.isEmpty(schoolCountMap)){
            BigDecimal bigDecimal= (BigDecimal) schoolCountMap.get("schoolCount");
            ybmOverviewVO.setSchoolCount(bigDecimal.intValue());
        }else{
            ybmOverviewVO.setSchoolCount(0);
        }
        //学校同比增长数
        QueryWrapper<EduSjtj03> schoolIncreaseCountWrapper=new QueryWrapper<>();
        schoolIncreaseCountWrapper.select("sum(target_num) as schoolIncreaseCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0043");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            schoolIncreaseCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            schoolIncreaseCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> schoolIncreaseCountMap=eduSjtj03Service.getMap(schoolIncreaseCountWrapper);
        if(!ObjectUtils.isEmpty(schoolIncreaseCountMap)){
            BigDecimal bigDecimal= (BigDecimal) schoolIncreaseCountMap.get("schoolIncreaseCount");
            ybmOverviewVO.setSchoolIncreaseCount(bigDecimal.intValue());
        }else{
            ybmOverviewVO.setSchoolIncreaseCount(0);
        }


        //学位总数
        QueryWrapper<EduSjtj03> degreeCountWrapper=new QueryWrapper<>();
        degreeCountWrapper.select("sum(target_num) as degreeCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0044");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            degreeCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            degreeCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> degreeCountMap=eduSjtj03Service.getMap(degreeCountWrapper);
        if(!ObjectUtils.isEmpty(degreeCountMap)){
            BigDecimal bigDecimal= (BigDecimal) degreeCountMap.get("degreeCount");
            ybmOverviewVO.setDegreeCount(bigDecimal.intValue());
        }else{
            ybmOverviewVO.setDegreeCount(0);
        }
        //学位同比增长数
        QueryWrapper<EduSjtj03> degreeIncreaseCountWrapper=new QueryWrapper<>();
        degreeIncreaseCountWrapper.select("sum(target_num) as degreeIncreaseCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0045");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            degreeIncreaseCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            degreeIncreaseCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> degreeIncreaseCountMap=eduSjtj03Service.getMap(degreeIncreaseCountWrapper);
        if(!ObjectUtils.isEmpty(degreeIncreaseCountMap)){
            BigDecimal bigDecimal= (BigDecimal) degreeIncreaseCountMap.get("degreeIncreaseCount");
            ybmOverviewVO.setDegreeIncreaseCount(bigDecimal.intValue());
        }else{
            ybmOverviewVO.setDegreeIncreaseCount(0);
        }
        //总计划招生
        QueryWrapper<EduSjtj03> studentJhCountWrapper=new QueryWrapper<>();
        studentJhCountWrapper.select("sum(target_num) as studentJhCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0046");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            studentJhCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            studentJhCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> studentJhCountMap=eduSjtj03Service.getMap(studentJhCountWrapper);
        if(!ObjectUtils.isEmpty(studentJhCountMap)){
            BigDecimal bigDecimal= (BigDecimal) studentJhCountMap.get("studentJhCount");
            ybmOverviewVO.setStudentJhCount(bigDecimal.intValue());
        }else{
            ybmOverviewVO.setStudentJhCount(0);
        }
        //预报名人数
        QueryWrapper<EduSjtj03> studentYbmCountWrapper=new QueryWrapper<>();
        studentYbmCountWrapper.select("sum(target_num) as studentYbmCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0047");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            studentYbmCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            studentYbmCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> studentYbmCountMap=eduSjtj03Service.getMap(studentYbmCountWrapper);
        if(!ObjectUtils.isEmpty(studentYbmCountMap)){
            BigDecimal bigDecimal= (BigDecimal) studentYbmCountMap.get("studentYbmCount");
            ybmOverviewVO.setStudentYbmCount(bigDecimal.intValue());
        }else{
            ybmOverviewVO.setStudentYbmCount(0);
        }
        //适龄人数
        QueryWrapper<EduSjtj03> studentSlCountWrapper=new QueryWrapper<>();
        studentSlCountWrapper.select("sum(target_num) as studentSlCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0048");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            studentSlCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            studentSlCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> studentSlCountMap=eduSjtj03Service.getMap(studentSlCountWrapper);
        if(!ObjectUtils.isEmpty(studentSlCountMap)){
            BigDecimal bigDecimal= (BigDecimal) studentSlCountMap.get("studentSlCount");
            ybmOverviewVO.setStudentSlCount(bigDecimal.intValue());
        }else{
            ybmOverviewVO.setStudentSlCount(0);
        }
        return ybmOverviewVO;
    }

    @Override
    public InformationCollectionVO getInformationCollection(YbmOverviewQueryVO vo) {
        InformationCollectionVO informationCollectionVO =new InformationCollectionVO();
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        informationCollectionVO.setYear(vo.getYear());
        informationCollectionVO.setAreaCode(vo.getAreaCode());

        //已采集报名信息
        QueryWrapper<EduSjtj03> applyInfoWrapper=new QueryWrapper<>();
        applyInfoWrapper.select("sum(target_num) as applyInfo").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0049");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            applyInfoWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            applyInfoWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> applyInfoMap=eduSjtj03Service.getMap(applyInfoWrapper);
        if(!ObjectUtils.isEmpty(applyInfoMap)){
            BigDecimal bigDecimal= (BigDecimal) applyInfoMap.get("applyInfo");
            informationCollectionVO.setApplyInfo(bigDecimal.intValue());
        }else{
            informationCollectionVO.setApplyInfo(0);
        }
        //已核实信息
        QueryWrapper<EduSjtj03> verifyInfoWrapper=new QueryWrapper<>();
        verifyInfoWrapper.select("sum(target_num) as verifyInfo").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0050");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            verifyInfoWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            verifyInfoWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> verifyInfoWrapperMap=eduSjtj03Service.getMap(verifyInfoWrapper);
        if(!ObjectUtils.isEmpty(verifyInfoWrapperMap)){
            BigDecimal bigDecimal= (BigDecimal) verifyInfoWrapperMap.get("applyInfo");
            informationCollectionVO.setVerifyInfo(bigDecimal.intValue());
        }else{
            informationCollectionVO.setVerifyInfo(0);
        }
        //核实通过
        QueryWrapper<EduSjtj03> verifyThroughWrapper=new QueryWrapper<>();
        verifyThroughWrapper.select("sum(target_num) as verifyThrough").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0051");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            verifyThroughWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            verifyThroughWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> verifyThroughMap=eduSjtj03Service.getMap(verifyThroughWrapper);
        if(!ObjectUtils.isEmpty(verifyThroughMap)){
            BigDecimal bigDecimal= (BigDecimal) verifyThroughMap.get("verifyThrough");
            informationCollectionVO.setVerifyThrough(bigDecimal.intValue());
        }else{
            informationCollectionVO.setVerifyThrough(0);
        }
        //未核实通过
        QueryWrapper<EduSjtj03> verificationFailedWrapper=new QueryWrapper<>();
        verificationFailedWrapper.select("sum(target_num) as verificationFailed").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0052");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            verificationFailedWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            verificationFailedWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> verificationFailedMap=eduSjtj03Service.getMap(verificationFailedWrapper);
        if(!ObjectUtils.isEmpty(verificationFailedMap)){
            BigDecimal bigDecimal= (BigDecimal) verificationFailedMap.get("verificationFailed");
            informationCollectionVO.setVerificationFailed(bigDecimal.intValue());
        }else{
            informationCollectionVO.setVerificationFailed(0);
        }
        return informationCollectionVO;
    }

    @Override
    public VerifyDataVO getVerifyInfo(YbmOverviewQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        VerifyDataVO verifyDataVO=new VerifyDataVO();
        verifyDataVO.setYear(vo.getYear());
        verifyDataVO.setAreaCode(vo.getAreaCode());
        //户籍数据
        QueryWrapper<EduSjtj03> censusCountWrapper=new QueryWrapper<>();
        censusCountWrapper.select("sum(target_num) as censusCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0053");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            censusCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            censusCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> censusCountMap=eduSjtj03Service.getMap(censusCountWrapper);
        if(!ObjectUtils.isEmpty(censusCountMap)){
            BigDecimal bigDecimal= (BigDecimal) censusCountMap.get("censusCount");
            verifyDataVO.setCensusCount(bigDecimal.intValue());
        }else{
            verifyDataVO.setCensusCount(0);
        }
        //房产数据
        QueryWrapper<EduSjtj03> houseCountWrapper=new QueryWrapper<>();
        houseCountWrapper.select("sum(target_num) as houseCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0054");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            houseCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            houseCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> houseCountMap=eduSjtj03Service.getMap(houseCountWrapper);
        if(!ObjectUtils.isEmpty(houseCountMap)){
            BigDecimal bigDecimal= (BigDecimal) houseCountMap.get("houseCount");
            verifyDataVO.setHouseCount(bigDecimal.intValue());
        }else{
            verifyDataVO.setHouseCount(0);
        }
        //网签数据
        QueryWrapper<EduSjtj03> webCountWrapper=new QueryWrapper<>();
        webCountWrapper.select("sum(target_num) as webCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0055");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            webCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            webCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> webCountMap=eduSjtj03Service.getMap(webCountWrapper);
        if(!ObjectUtils.isEmpty(webCountMap)){
            BigDecimal bigDecimal= (BigDecimal) webCountMap.get("webCount");
            verifyDataVO.setWebCount(bigDecimal.intValue());
        }else{
            verifyDataVO.setWebCount(0);
        }
        //人社数据
        QueryWrapper<EduSjtj03> crowdCountWrapper=new QueryWrapper<>();
        crowdCountWrapper.select("sum(target_num) as crowdCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0056");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            crowdCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            crowdCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> crowdCountMap=eduSjtj03Service.getMap(crowdCountWrapper);
        if(!ObjectUtils.isEmpty(crowdCountMap)){
            BigDecimal bigDecimal= (BigDecimal) crowdCountMap.get("crowdCount");
            verifyDataVO.setCrowdCount(bigDecimal.intValue());
        }else{
            verifyDataVO.setCrowdCount(0);
        }
        //企业数据
        QueryWrapper<EduSjtj03> companyCountWrapper=new QueryWrapper<>();
        companyCountWrapper.select("sum(target_num) as companyCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0057");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            companyCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            companyCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> companyCountMap=eduSjtj03Service.getMap(companyCountWrapper);
        if(!ObjectUtils.isEmpty(companyCountMap)){
            BigDecimal bigDecimal= (BigDecimal) companyCountMap.get("companyCount");
            verifyDataVO.setCompanyCount(bigDecimal.intValue());
        }else{
            verifyDataVO.setCompanyCount(0);
        }
        //居住证数据
        QueryWrapper<EduSjtj03> liveCountWrapper=new QueryWrapper<>();
        liveCountWrapper.select("sum(target_num) as liveCount").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode()).eq("Target_Code","Y0057");
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            liveCountWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            liveCountWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String,Object> liveCountMap=eduSjtj03Service.getMap(liveCountWrapper);
        if(!ObjectUtils.isEmpty(liveCountMap)){
            BigDecimal bigDecimal= (BigDecimal) liveCountMap.get("liveCountMap");
            verifyDataVO.setLiveCount(bigDecimal.intValue());
        }else{
            verifyDataVO.setLiveCount(0);
        }
        //总数
        verifyDataVO.setCount(verifyDataVO.getCensusCount()+ verifyDataVO.getCrowdCount()+ verifyDataVO.getCompanyCount()+ verifyDataVO.getHouseCount()+ verifyDataVO.getLiveCount()+ verifyDataVO.getWebCount());
        return verifyDataVO;
    }

    @Override
    public KindOfApplyVO getKindOfApplyInfo(YbmOverviewQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        KindOfApplyVO kindOfApplyVO=new KindOfApplyVO();
        kindOfApplyVO.setAreaCode(vo.getAreaCode());
        kindOfApplyVO.setYear(vo.getYear());
        QueryWrapper<EduSjtj02> wrapper=new QueryWrapper<>();
        wrapper.select("sum(A1) as A1","sum(B1) as B1","sum(C1) as C1").eq("year",vo.getYear()).eq("Area_Code",vo.getAreaCode());
        List<EduSjtj02> list=eduSjtj02Service.list(wrapper);
        List<KindOfApplyTypeVO> kindOfApplyTypeVOList=new ArrayList<>();
        if(list.size()>0){
            list.forEach(item->{
                KindOfApplyTypeVO kindOfApplyTypeVO=new KindOfApplyTypeVO();
                kindOfApplyTypeVO.setType("A类");
                kindOfApplyTypeVO.setCount(item.getA1().intValue());
                kindOfApplyTypeVO.setType("B类");
                kindOfApplyTypeVO.setCount(item.getB1().intValue());
                kindOfApplyTypeVO.setType("C类");
                kindOfApplyTypeVO.setCount(item.getC1().intValue());
                kindOfApplyTypeVOList.add(kindOfApplyTypeVO);
            });
        }else{

        }


        return kindOfApplyVO;
    }

    @Override
    public PreNameRankVO getPreNameRankList(YbmOverviewQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        PreNameRankVO preNameRankVO=new PreNameRankVO();
        preNameRankVO.setYear(vo.getYear());
        preNameRankVO.setAreaCode(vo.getAreaCode());


        List<PreNameRankListVO> preNameRankListVOS =eduSjtj02Service.getPreNameRankingList(vo);
        preNameRankVO.setList(preNameRankListVOS.subList(0,Math.min(preNameRankListVOS.size(),20)));
        return preNameRankVO;
    }

    @Override
    public List<EduSjtj02RankVO> getAreaRankList(YbmOverviewQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        EduSjtj02InVO eduSjtj02InVO=new EduSjtj02InVO();
        eduSjtj02InVO.setYear(vo.getYear());
        eduSjtj02InVO.setAreaCode(vo.getAreaCode());
        List<EduSjtj02RankVO> list=eduSjtj02Service.getRankList(eduSjtj02InVO);

        Integer[] arr={1};
        list=list.stream().peek(e->e.setRowNum(arr[0]++)).collect(Collectors.toList());

        return list.subList(0,Math.min(list.size(),5));
    }

    @Override
    public Map<String,Object> getFiveYearInfo(SchoolQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        Map<String,Object> param=new HashMap<>();
        param.put("year",vo.getYear());
        param.put("schoolId",vo.getSchoolId());

        Map<String,Object> result=new HashMap<>();
        result.put("fiveYearList",eduSjtj02Service.getDegreeSchFiveYearInfo(param));
        EduSjtj02 eduSjtj02=eduSjtj02Service.getOne(new QueryWrapper<EduSjtj02>().eq("school_id",vo.getSchoolId()));
        result.put("wy",eduSjtj02.getWy());
        result.put("enrolment",eduSjtj02.getEnrolment());
        result.put("name",eduSjtj02.getSchoolName());
        return result;
    }

    private GetDictVO getDictName(GetDictVO vo){
        if("1".equals(vo.getAstype())){
            DictQueryVO dictQueryVO = new DictQueryVO();
            dictQueryVO.setDictField(vo.getDictField());
            dictQueryVO.setDictKey(vo.getDictKey());
            vo.setDictValue(dictIntegration.getValue(dictQueryVO));
        }else {
            QueryWrapper<EduArea> qwpre = new QueryWrapper<>();
            qwpre.select("Area_Name")
                    .eq("local_code", vo.getDictField());
            Map<String, Object> map = eduAreaService.getMap(qwpre);
            if (!ObjectUtils.isEmpty(map)) {
                vo.setDictValue(map.get("Area_Name").toString());
            }
        }
        return vo;
    }
}
